using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace DataLayerTest.Models.Mapping
{
    public class PlayerMap : EntityTypeConfiguration<Player>
    {
        public PlayerMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.IDCode)
                .IsRequired()
                .HasMaxLength(255);

            this.Property(t => t.ThumbnailUrl)
                .HasMaxLength(255);

            // Table & Column Mappings
            this.ToTable("Player");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.IdFitbitAccount).HasColumnName("IdFitbitAccount");
            this.Property(t => t.IDCode).HasColumnName("IDCode");
            this.Property(t => t.IdPlayerGroup).HasColumnName("IdPlayerGroup");
            this.Property(t => t.IdProfessional).HasColumnName("IdProfessional");
            this.Property(t => t.IdAdministrator).HasColumnName("IdAdministrator");
            this.Property(t => t.BirthDate).HasColumnName("BirthDate");
            this.Property(t => t.IdState).HasColumnName("IdState");
            this.Property(t => t.BBS).HasColumnName("BBS");
            this.Property(t => t.ThumbnailUrl).HasColumnName("ThumbnailUrl");

            // Relationships
            this.HasRequired(t => t.Administrator)
                .WithMany(t => t.Players)
                .HasForeignKey(d => d.IdAdministrator);
            this.HasOptional(t => t.FitbitAccount)
                .WithMany(t => t.Players)
                .HasForeignKey(d => d.IdFitbitAccount);
            this.HasOptional(t => t.PlayerGroup)
                .WithMany(t => t.Players)
                .HasForeignKey(d => d.IdPlayerGroup);
            this.HasRequired(t => t.User)
                .WithOptional(t => t.Player);
            this.HasOptional(t => t.Professional)
                .WithMany(t => t.Players)
                .HasForeignKey(d => d.IdProfessional);
            this.HasRequired(t => t.StateType)
                .WithMany(t => t.Players)
                .HasForeignKey(d => d.IdState);

        }
    }
}
